<?php
$id_category = (isset($this->pageValues['id_category'])) ? $this->pageValues['id_category'] : '';
if(empty($id_category))
{
	if (!empty($this->product))
	{
		$customCategory = $this->product->getCustomCategory();
		if(!empty($customCategory))
		{
			$id_category = $customCategory->path . '%';
		}
	}
}
echo $this->menuBuilder($this->menus, $id_category);
?>

<div class="orange_line">&nbsp;</div>
	<?php echo $this->form;?>
    <?php if(empty($this->store->shopping_cart_setting)): ?>
        <?php if(!empty($this->pageValues['form_submitted'])):?>
            <?php if(!empty($this->pageValues['keyword']) || !empty($this->pageValues['category'])):?>
                <div class="result_container">
                    <?php 
                        $order = array('url','item_count','keyword','category');
                        $keys  = array('keyword', 'category');
                        echo $this->results($this->form, $keys, $this->pageValues, $order,$this->url);
                    ?>
                    - <a id="reset" href="<?php echo $this->pageUrl(array('module' => 'tab', 'target' => 'index'), true) ?>" class="icon_reset" title="<?php echo $this->translate('Reset')?>"></a>
                </div>
            <?php endif;?>
        <?php endif;?>

        <?php if (!empty($this->product)): ?>
            <div class="bread-crumb_container">
                <?php echo $this->partial('index/_breadscrumb.phtml', array('breadscrumb' => $this->product->getCustomBreadscrumb($this->path))); ?>
            </div>
        <?php endif;?>
    <?php else: ?>
    <div class="search_info">
        <?php if(!empty($this->pageValues['form_submitted'])):?>
            <?php if(!empty($this->pageValues['keyword']) || !empty($this->pageValues['category'])):?>
                <div class="result_container">
                    <?php 
                        $order = array('url','item_count','keyword','category');
                        $keys  = array('keyword', 'category');
                        echo $this->results($this->form, $keys, $this->pageValues, $order,$this->url);
                    ?>
                    - <a id="reset" href="<?php echo $this->pageUrl(array('module' => 'tab', 'target' => 'index'), true) ?>" class="icon_reset" title="<?php echo $this->translate('Reset')?>"></a>
                </div>
            <?php endif;?>
        <?php endif;?>
        
        <?php if (!empty($this->product)): ?>
            <div class="bread-crumb_container">
                <?php echo $this->partial('index/_breadscrumb.phtml', array('breadscrumb' => $this->product->getCustomBreadscrumb($this->path))); ?>
            </div>
        <?php endif;?>
    </div>
    <div class="cart_info">
        <a title="<?php echo $this->translate('SHOPPING_CART');?>" target="_top" href="<?php echo $this->social->pageUrl( array('redirect_url' => $this->pageUrl(array('module' => 'tab', 'target' => 'cart'),true)), $this->id_page);?>" 
           id="shopping_cart" class="shopping_cart tooltip_label">
            <span>0</span>
        </a>
    </div>
    <?php endif;?>

<?php 
if (!empty($this->product)): 
/* @var $this->product Core_Model_Product */
?>
<div style="clear:both">&nbsp;</div>
<div style="clear:both">
	<div class="sm_gallery">
		<div class="">
			<div class="container">				
				<div class="lookup">
					<a href='<?php echo $this->product->getPrimaryImageUrl() ?>' class='cloud-zoom' id='zoom1'
						rel="adjustX: 10, adjustY:-1,showTitle: false">						
						<img src="<?php echo $this->product->getPrimaryImageUrl() ?>" id="pkImage" title="<?php echo $this->escape($this->product->getPrimaryImageDescription())?>"/>
					</a>
				</div>				
			</div>
			<div class="image-slider">
				<ol class="list_images">
					<?php 
						$is_first	= true;
						$arrImages	= array();
						foreach ($this->product->getListProductImages() as $image): ?>
						<?php $arrImages[] = STATIC_URL . '/upload/product/' .$image->image; ?>
						<li href="<?php echo STATIC_URL . '/upload/product/' .$image->image ?>"
							class="cloud-zoom-gallery <?php echo $is_first?'active':'' ?>"
							rel="useZoom: 'zoom1', smallImage: '<?php echo STATIC_URL . '/upload/product/' .$image->image ?>'"
							title="<?php echo $this->escape($image->description)?>"><img src="<?php echo STATIC_URL . '/upload/product/thumbnail/' .$image->image ?>" alt="<?php echo $this->escape($image->description)?>"/></li>
					<?php $is_first = false; endforeach; ?>
				</ol>
			</div>
		</div>
        <?php if($this->store->is_allow_comment == Core_Model_DbTable_Stores::STATUS_ALLOW_COMMENT):?>
		<div class="sm_comment">
			<?php
			echo $this->social->render('comment', array(
				'url'	=> $this->product->getShareUrl(array('id_page' => $this->social->getIdPage())),
				'width' => '400'
			))
			?>
		</div>
        <script type="text/javascript">
            $(document).ready(function(){
                var ajax_url = '<?php echo $this->baseUrl('/store/index/notify')?>';
	            var data = {
                    id_product: "<?php echo $this->product->id?>",
                    id_store: "<?php echo $this->product->id_store?>",
                    id_page: "<?php echo $this->id_page?>"
                }
                Social.handleCommentNotify(ajax_url, data);
            });
        </script>
        <?php endif;?>
	</div>
	<div class="product_detail">
		<span class="name">
		<?php echo $this->escape($this->product->getName());
		if ($this->social->isPageAdmin()): ?>		
		<a href="<?php echo $this->socialUrl(array('module' => 'store', 'controller' => 'product', 'action' => 'edit', 'id_store' => $this->product->id_store,  'id_page' => $this->social->getIdPage(), 'id' => $this->product->id),'default',true); ?>" target="_blank">(<?php echo $this->translate('Edit');?>)</a>
		<?php endif;?>
		</span>
		<?php if( !empty($this->product->price) || !empty($this->product->link) || !empty($this->store->shopping_cart_setting)):?>
			<div class="detail_row price">
				
				<?php if(!empty($this->product->old_price)):?>
					<div class="sm_price big"><span class="sale_price">  <?php echo (!empty($this->product->price))? $this->product->getPrice() : '&nbsp;'?></span><br><span class='old_price' ><?php echo $this->product->getOldPrice() ?></div> 
                <?php else :?>
                    <div class="sm_price big"><span class="sale_price"><?php echo (!empty($this->product->price))? $this->product->getPrice() : '&nbsp;'?></span></div>
				<?php endif;?>
				<?php if(empty($this->store->shopping_cart_setting)): ?>
                    <?php if(!empty($this->product->link)):?>		
                        <a 
                            href="<?php echo $this->escape($this->product->getLink());?>"
                            value="<?php echo $this->product->id;?>"
                            class="btn_buynow buys"
                            <?php if( $this->product->linkIsUrl() ): ?>
                                target="_blank"
                            <?php endif;?>
                        >
                            <?php echo $this->translate('BUY_NOW') ?>
                        </a>
                    <?php endif;?>
                <?php else:?>
                    <a id="btn_add_to_cart"
                        href="#"
                        value="<?php echo $this->product->id;?>"
                        class="btn_buynow add_to_card"
                    >
                        <?php echo $this->translate('ADD_TO_CART') ?>
                    </a>
                <?php endif;?>
				&nbsp;
			</div>
		<?php endif;?>
		
		<?php if(!empty($this->product->sku)):?>
			<div class="detail_row sku">
				<strong><?php echo $this->translate('SKU') ?>: <?php echo $this->escape($this->product->sku);?></strong>
			</div>
		<?php else:?>
			<div style="clear:both;height: 0px">&nbsp;</div>
		<?php endif;?>
		<div class="detail_row description">
			<?php echo $this->product->description;?>
		</div>
		<div class="detail_row like_share">
			<?php echo $this->social->render('recommendUrl', array(
				'url'			=>  $this->product->getShareUrl(array('id_page' => $this->social->getIdPage())),
				'product'		=>	$this->product,
				'pageValues'	=>	$this->pageValues,
				'horizontal'	=>	true,
				'requestMessage' => $this->translate('REQUEST_MESSAGE'),
				'send' => false,
				'width' => 'auto',
				'show_faces'=>false
			)); ?>
		</div>
		<div class="detail_row shorturl" style="width:100%; position:relative;">
			<div style="width:100%; position:relative;">
				<span><?php echo $this->translate('Permanent link')?>:</span> <a href="<?php echo $this->product->getShortenerUrl(array('id_page' => $this->social->getIdPage())); ?>" class="short_url"><?php echo $this->translate('Short link')?></a><span> | </span><a href="<?php echo $this->product->getShareUrl(array('id_page' => $this->social->getIdPage()),true) ?>" class="long_url"><?php echo $this->translate('Long link')?></a>
			</div>
			<div class="url_pannel">
				<input name="link" readonly value="">
			</div>
		</div>
		<?php if (count($this->relatedProducts)):?>
		<div class="related_product">
			<h2><?php echo $this->translate('Related products')?></h2>
			<ul>
				<?php for ($i = 0 ; ($i < count($this->relatedProducts) && $i < MAX_RELATED_PRODUCT); $i++):?>
				<?php $relatedProduct = $this->relatedProducts[$i];?>
				<li>
					<div class="image_container">
						<a href="<?php echo $this->pageUrl(array_merge($this->pageValues, array('target' => 'detail', 'id_product' => $relatedProduct->id))); ?>">
							<img title="" src="<?php echo $relatedProduct->getPrimaryImageUrl() ?>" class="pic_item">
						</a>
					</div>
					<div class="produc_info">
						<div class="product_name">
							<a href="<?php echo $this->pageUrl(array_merge($this->pageValues, array('target' => 'detail', 'id_product' => $relatedProduct->id))); ?>"><?php  echo $relatedProduct->getName();?></a>
						</div>
                        <div class="sm_price right">
                        <?php if(!empty($relatedProduct->old_price)):?>
                            <span class='sale_price'> <?php echo (!empty($relatedProduct->price))? $relatedProduct->getPrice() : '&nbsp;'?><br></span><span class='old_price' ><?php echo $relatedProduct->getOldPrice() ?></span>
                        <?php else :?>
                            <span class="sale_price"><?php echo (!empty($relatedProduct->price))? $relatedProduct->getPrice() : '&nbsp;'?></span>
                        <?php endif;?>
                        </div>    
					</div>
				</li>
				<?php endfor;?>
			</ul>
		</div>
		<?php endif;?>
	</div>
</div>
<?php else: ?>
	<div class="msg_panel"><?php echo sprintf($this->translate('FRONTEND_WARNING_NOTFOUND_PRODUCT'), 'product'); ?></div>
<?php endif; ?>
<?php echo $this->partial('index/scrollTop.phtml');?>
<script type="text/javascript">		
    $('.recommend_back').ymProductItem({
		'hover' : false
	});
	$('.detail_row.shorturl').ymProductShareUrl({
		'short-url' : '<?php echo $this->product->getShortenerUrl(array('id_page' => $this->social->getIdPage())); ?>',
		'long-url' : '<?php echo $this->product->getShareUrl(array('id_page' => $this->social->getIdPage())) ?>'
	});
	$(document).ready(function() {	
        $('.buys').click(function(){
			var id_product = $(this).attr('value');
			$.ajax({
				type: 'POST',
				url: '<?php echo $this->pageUrl(array('module' => 'tab', 'target' => 'buys'), '', true); ?>',
				data: {'id_product': id_product},
				success: function(data){}
			});		
		});
		try{
			var arrImages = <?php echo json_encode($arrImages) ?>;
			for(i = 1; i < arrImages.length; i++ )
			{
				var img = new Image();
				img.src = arrImages[i];
			}
		}
		catch(e)
		{
			
		}
    });
</script>
<?php if(!empty($this->store->shopping_cart_setting)): ?>
<script type="text/javascript">
    var id_store    = '<?php echo $this->store->id?>';
    var cookie_path = '<?php echo $this->pageUrl(array('id_page' => $this->id_page), true);?>';
    var label_item  = '<?php echo $this->translate('ITEM');?>';
    var label_items  = '<?php echo $this->translate('ITEMS');?>';
    var shopping_cart_link = '<?php echo $this->social->pageUrl( array('redirect_url' => $this->pageUrl(array('module' => 'tab', 'target' => 'cart'),true)), $this->id_page);?>';
    var current_date    = new Date();
    var time_expired    = Date.parse(current_date) + 24*60*60;
    var msg_add_cart_successfull_n_items = '<?php echo $this->translate('SUCCESSFUL_ADD_TO_SHOPPING_CART_N_ITEMS');?>';
    var msg_add_cart_successfull_n_item  = '<?php echo $this->translate('SUCCESSFUL_ADD_TO_SHOPPING_CART_N_ITEM');?>';

    $(document).ready(function(){
        loadItemsNumber();
        $('#btn_add_to_cart').click(function(){
            var id_product = $(this).attr('value');
            <?php if($this->is_authorized == true):?>
                addToCart(id_product);
            <?php else:?>
                authorizeBeforeAddToCart(function(){
                    addToCart(id_product);
                });
            <?php endif;?>
        });
        
        $('.tooltip_label').tipsy();
    });
</script>
<?php endif;?>